package com.gitee.qdbp.general.system.web.controlling.handler;

import java.lang.reflect.Field;
import com.gitee.qdbp.able.beans.AcceptAttrs;
import com.gitee.qdbp.able.exception.ServiceException;
import com.gitee.qdbp.base.enums.OperateType;
import com.gitee.qdbp.base.model.consts.Keys;
import com.gitee.qdbp.base.system.model.IAccount;

public class DeptCodeAcceptHandler extends AcceptAttrsSimpleHandler<String> {

    @Override
    protected String getUserAttrs(Object o, Field field, String dataType, OperateType operateType, IAccount user) {
        return user.getDeptCode();
    }

    @Override
    protected AcceptAttrs<String> getCurrentAcceptAttrs(Object o, Field field, String dataType, OperateType operateType,
            String deptCode) throws ServiceException {

        AcceptAttrs<String> attrs = new AcceptAttrs<>();
        attrs.setStarts(true);
        if (Keys.ROOT_CODE.equals(deptCode)) {
            attrs.setAll(true);
        } else {
            attrs.setDefaultValue(deptCode);
            attrs.addAcceptValue(deptCode);
        }
        return attrs;
    }

}
